package fr.castorhoz.isi_connectivity_widget;

import android.content.Context;
import android.util.Log;
import fr.castorhoz.isi_connectivity_widget.bluetooth_widget.BluetoothButton;
import fr.castorhoz.isi_connectivity_widget.gps_widget.GPSButton;
import fr.castorhoz.isi_connectivity_widget.mobiledata_widget.MobileDataButton;
import fr.castorhoz.isi_connectivity_widget.roaming_widget.RoamingButton;
import fr.castorhoz.isi_connectivity_widget.wifi_widget.WifiButton;

public abstract class ConnButton {
	public static int selector_on;
	public static int selector_off;
	public static int selector_unknown;
	
	protected int appWidgetId;
	
	public enum widgets {
		bluetoohWidget,
		wifiWidget,
		mobileDataWidget,
		gpsWidget,
		roamingWidget;
		
		public static int getAdaptedDrawableId(String widgetName) {
			int retour = -1;
			switch (widgets.valueOf(widgetName)) {
			case bluetoohWidget:
				retour = R.drawable.bluetoothwidget;
				break;
			case gpsWidget:
				retour = R.drawable.gpswidget;
				break;
			case mobileDataWidget:
				retour = R.drawable.mobiledatawidget;
				break;
			case roamingWidget:
				retour = R.drawable.roamingwidget;
				break;
			case wifiWidget:
				retour = R.drawable.wifiwidget;
				break;

			default:
				break;
			}
			return retour;		
		}
		
	};
	
	public enum widgetsActions {
		fr_imberle_connectivityWidget_CLICK_WIFI,
		fr_imberle_connectivityWidget_CLICK_BLUETOOTH,
		fr_imberle_connectivityWidget_CLICK_ROAMING,
		fr_imberle_connectivityWidget_CLICK_GPS,
		fr_imberle_connectivityWidget_CLICK_MOBILEDATA;
		public static ConnButton getGenericButtonFromAction(String action) {
			ConnButton button = null;
			switch (widgetsActions.valueOf(action)) {
			case fr_imberle_connectivityWidget_CLICK_WIFI:
				button = new WifiButton();
				break;
			case fr_imberle_connectivityWidget_CLICK_BLUETOOTH:
				button = new BluetoothButton();
				break;
			case fr_imberle_connectivityWidget_CLICK_ROAMING:
				button = new RoamingButton();
				break;
			case fr_imberle_connectivityWidget_CLICK_GPS:
				button = new GPSButton();
				break;
			case fr_imberle_connectivityWidget_CLICK_MOBILEDATA:
				button = new MobileDataButton();
				break;
			default:
				break;
			}
			
			return button;
		}
	};
	
	public abstract boolean getState(Context context);
	
	public void switchNetwork(Context context) {
		if (getState(context)) {
			Log.d(this.getClass().getName(), "disabling the fonctionnality");
			disableNetwork(context);
		} else {
			Log.d(this.getClass().getName(), "enabling the fonctionnality");
			enableNetwork(context);
		}
	}

	public abstract void disableNetwork(Context c);

	public abstract void enableNetwork(Context c);

	public abstract String getAction();
	
	public abstract int getSelectorUnknown();
	
	public abstract int getSelectorOn();
	
	public abstract int getSelectorOff();

	public abstract int getCurrentSelector();

}
